// pages/register/register.ts
//import { ProfileService } from "../../service/profile"
//import { rental } from "../../service/proto_gen/rental/rental_pb"
//import { Coolcar } from "../../service/request"
//import { padString } from "../../utils/format"
import { routing } from "../../utils/routing"
Page({
    redirectURL: '',
    profileRefresher: 0,  
    data:{
      licNo: '',
      name: '',
      genderIndex: 0,
      genders: ['未知', '男', '女'],
      birthDate: '1990-01-01',
      licImgURL: '/resources/sedan.png',
      state: 'UNSUBMITTED',
    },
    onLoad(opt: Record<'redirect', string>) {
      const o: routing.RegisterOpts = opt
      if(o.redirect) {
          this.redirectURL = decodeURIComponent(o.redirect)
      }
      // ProfileService.getProfile().then(p => this.renderProfile(p))
      // ProfileService.getProfilePhoto().then(p => {
      //     this.setData({
      //         licImgURL: p.url||'',
      //     })
      // })
    },    
    onUploadLic(){
      wx.chooseImage({
        success:res=>{
          if (res.tempFilePaths.length === 0) {
            return
          }
          this.setData({
            licImgURL:res.tempFilePaths[0],
          })
        }
      })
    },
    onGenderChange(e: any) {
      console.log(e)
      this.setData({
          genderIndex: parseInt(e.detail.value),
      })
    },

  onBirthDateChange(e: any) {
      this.setData({
          birthDate: e.detail.value,
      })
    },
  onSubmit(){
    this.setData({
      state: 'PENDING',
    })
    setTimeout(()=>{
      this.onLicVerified()
    },5000)
  },
  onResubmit() {
    this.setData({
      state: 'UNSUBMITTED',
      licImgURL: '',
  })
  },

  onLicVerified() {
    if (this.redirectURL) {
        wx.redirectTo({
            url: this.redirectURL,
        })
    }
  }  
})